package cn.GUI;

import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class Frame_demo {
	public static void main(String[] args) {
		Frame f =new Frame("hello word");
		f.setSize(400,300);
		f.setLocation(400, 100);
		f.setIconImage(Toolkit.getDefaultToolkit().createImage("./test/img/h.png"));
		Button b1 = new Button("one");
		Button b2 = new Button("two");
		f.add(b1);
		f.add(b2);
		f.setLayout(new FlowLayout());
		f.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {	
				System.exit(0);
			}
		});
		b1.addMouseListener(new MouseAdapter() {
			/*@Override
			public void mouseClicked(MouseEvent e) {
				System.exit(0);
			}*/
			@Override
			public void mouseReleased(MouseEvent e) {
				System.exit(0);
				
			}
		});
		b1.addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent e) {
				// System.exit(0);
//				System.out.println(e.getKeyCode());
//				if(e.getKeyCode() == 27)
//					System.exit(0);
				if(e.getKeyCode() == KeyEvent.VK_ALT)
					System.exit(0);
			}
		});
		f.setVisible(true);
	}
}
